#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
检查Flask路由配置
"""

import sys
import os
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
PROJECT_ROOT = os.path.dirname(CURRENT_DIR)
if PROJECT_ROOT not in sys.path:
    sys.path.insert(0, PROJECT_ROOT)

from backend.app import create_app

def check_routes():
    """检查所有路由"""
    app = create_app()
    
    print("=== Flask 路由列表 ===")
    for rule in app.url_map.iter_rules():
        methods = ','.join(rule.methods - {'HEAD', 'OPTIONS'})
        print(f"{rule.rule:<50} {methods:<15} {rule.endpoint}")
    
    print("\n=== 检查特定路由 ===")
    target_route = '/api/netdisk/download/<path:file_path>'
    for rule in app.url_map.iter_rules():
        if 'download' in rule.rule and 'netdisk' in rule.rule:
            print(f"找到下载路由: {rule.rule} -> {rule.endpoint}")
            
            # 获取视图函数
            view_func = app.view_functions.get(rule.endpoint)
            if view_func:
                print(f"视图函数: {view_func.__name__}")
                print(f"装饰器: {getattr(view_func, '__wrapped__', '无')}")
                print(f"模块: {view_func.__module__}")
                
                # 检查是否有装饰器
                if hasattr(view_func, '__wrapped__'):
                    print("发现装饰器")
                else:
                    print("未发现装饰器")

if __name__ == "__main__":
    check_routes()